/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CastleDefense.units;

/**
 *
 * @author Administrator
 */
//import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.apache.commons.lang.StringUtils;

@XmlRootElement(name = "unit")
// If you want you can define the order in which the fields are written
// Optional
@XmlType(propOrder = { "name", "uclass", "sprite", "proj", "damage" , "atkmod", "range", "speed", "rof", "click", "effects", "cost"})
public class Unit
{
    private String   name;
    private String   uclass;
    private String   sprite;
    private String   proj;
    private int      damage;
    private double   atkmod;
    private double   range;
    private double   speed;
    private long     rof;
    private int      click;
    private String   effects;
    private int      cost;

    // If you dont like the variable name, e.g. "name", you can easily change this
    // variable name for your XML-Output:
    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    @XmlElement(name = "uclass")
    public String getUclass()
    {
        return uclass;
    }

    public void setUclass(String uclass)
    {
        this.uclass = uclass;
    }

    public String getSprite()
    {
        return sprite;
    }

    public void setSprite(String url)
    {
        this.sprite = url;
    }

    public String getSpriteClean()
    {
        String[] spriteArray = StringUtils.splitPreserveAllTokens(sprite, ',');

        return spriteArray[0];
    }

    @XmlElement(name = "proj")
    public String getProj()
    {
        return proj;
    }

    public void setProj(String proj)
    {
            this.proj = proj;
    }

    @XmlElement(name = "damage")
    public int getDamage()
    {
        return damage;
    }

    public void setDamage(int damage)
    {
        this.damage= damage;
    }

    @XmlElement(name = "atkmod")
    public double getAtkmod()
    {
        return atkmod;
    }

    public void setAtkmod(double atkmod)
    {
        this.atkmod = atkmod;
    }

    @XmlElement(name = "range")
    public double getRange()
    {
        return (range*42)+42;
    }

    public void setRange(double range)
    {
        this.range = range;
    }

    @XmlElement(name = "speed")
    public double getSpeed()
    {
        return speed;
    }

    public void setSpeed(double speed)
    {
        this.speed = speed;
    }

    @XmlElement(name = "rof")
    public long getRof()
    {
        return rof;
    }

    public void setRof(long rof)
    {
        this.rof = rof;
    }

    @XmlElement(name = "click")
    public int getClick()
    {
        return click;
    }

    public void setClick(int click)
    {
        this.click = click;
    }

    @XmlElement(name = "effects")
    public String getEffects()
    {
        return effects;
    }

    public int[] getStateEffects()
    {
        String[] stringArray = StringUtils.split(getEffects(), ',');
        int[]    effectArray = new int[stringArray.length];

        for(int i=0; i<stringArray.length;i++)
        {
            effectArray[i] = Integer.parseInt(stringArray[i]);
        }

        return effectArray;
    }

    public void setEffects(String effects)
    {
        this.effects = effects;
    }

    @XmlElement(name = "cost")
    public int getCost()
    {
        return cost;
    }

    public void setCost(int cost)
    {
        this.cost = cost;
    }

    public String getAllData()
    {
        String data = ""+getName()
                     +"\n"+getSprite()
                     +"\n"+getProj()
                     +"\n"+getDamage()
                     +"\n"+getAtkmod()
                     +"\n"+getRange()
                     +"\n"+getSpeed()
                     +"\n"+getClick()
                     +"\n"+getEffects()
                     +"\n"+getCost()+"\n";

        return data;
    }
}

